﻿using System;
using System.Collections.Generic;
using System.Text;

namespace CNVP.JShop.Publish
{
    /// <summary>
    /// URL获取类
    /// </summary>
    public class UrlUtils
    {
        #region "获取栏目地址"
        /// <summary>
        /// 获取栏目地址
        /// </summary>
        /// <param name="isHtml">是否为HTML</param>
        /// <param name="columnID">栏目ID</param>
        /// <returns>栏目地址URL字符串</returns>
        public static String GetColumnUrl(Boolean isHtml, Int32 columnID)
        {
            String columnUrl = String.Empty;
            if (isHtml)
            {
                columnUrl = CNVP.Config.UIConfig.HtmlFolder + columnID + @"/Index" + CNVP.Config.UIConfig.HtmlFileSuffix;
            }
            else
            {
                columnUrl = String.Format(CNVP.Config.UrlFormat.f_List, columnID);
            }
            return columnUrl;
        }
        #endregion
        #region "获取分页地址"
        /// <summary>
        /// 获取分页地址
        /// </summary>
        /// <param name="isHtml">是否为HTML</param>
        /// <param name="columnID">栏目ID</param>
        /// <param name="pageIndex">页码</param>
        /// <returns>分页地址URL字符串</returns>
        public static String GetPaginationUrl(Boolean isHtml, Int32 columnID, Int32 pageIndex)
        {
            String columnUrl = String.Empty;
            if (isHtml)
            {
                if (pageIndex == 1)
                {
                    columnUrl = CNVP.Config.UIConfig.HtmlFolder + columnID + @"/Index" + CNVP.Config.UIConfig.HtmlFileSuffix;
                }
                else
                {
                    columnUrl = CNVP.Config.UIConfig.HtmlFolder + columnID + @"/Index_" + pageIndex + CNVP.Config.UIConfig.HtmlFileSuffix;
                }
            }
            else
            {
                columnUrl = String.Format(CNVP.Config.UrlFormat.f_ListPage, columnID, pageIndex);
            }
            return columnUrl;
        }
        #endregion
        #region "获取内页地址"
        /// <summary>
        /// 获取内页地址
        /// </summary>
        /// <param name="isHtml">是否为HTML</param>
        /// <param name="columnID">栏目ID</param>
        /// <param name="dataID">信息ID</param>
        /// <param name="withColumn">是否包含栏目ID</param>
        /// <returns>内页地址URL字符串</returns>
        public static String GetDataUrl(Boolean isHtml, Int32 columnID, Int32 dataID, Boolean withColumn)
        {
            String dataUrl = String.Empty;
            if (isHtml)
            {
                dataUrl = CNVP.Config.UIConfig.HtmlFolder + columnID + @"/" + dataID + CNVP.Config.UIConfig.HtmlFileSuffix;
            }
            else
            {
                if (withColumn)
                {
                    dataUrl = String.Format(CNVP.Config.UrlFormat.f_DetailWithColumn, columnID, dataID);
                }
                else
                {
                    dataUrl = String.Format(CNVP.Config.UrlFormat.f_Detail, dataID);
                }
            }
            return dataUrl;
        }
        #endregion

        #region "获取文章内页地址"
        /// <summary>
        /// 获取文章内页地址
        /// </summary>
        /// <param name="isHtml">是否为HTML</param>
        /// <param name="columnID">栏目ID</param>
        /// <param name="dataID">信息ID</param>
        /// <param name="withColumn">是否包含栏目ID</param>
        /// <returns>内页地址URL字符串</returns>
        public static String GetNewUrl(Boolean isHtml, Int32 columnID, Int32 dataID, Boolean withColumn)
        {
            String dataUrl = String.Empty;
            if (isHtml)
            {
                dataUrl = CNVP.Config.UIConfig.HtmlFolder + columnID + @"/" + dataID + CNVP.Config.UIConfig.HtmlFileSuffix;
            }
            else
            {
                if (withColumn)
                {
                    dataUrl = String.Format(CNVP.Config.UrlFormat.f_NewsDetailWithColumn, columnID, dataID);
                }
                else
                {
                    dataUrl = String.Format(CNVP.Config.UrlFormat.f_NewsDetail, dataID);
                }
            }
            return dataUrl;
        }
        #endregion
    }
}
